package com.ashen.study.aop.dynamic;

import com.ashen.study.aop.patterns.Subject;
import com.ashen.study.aop.patterns.impl.SubjectImpl;

import java.lang.reflect.Proxy;

/**
 * @author hxl
 * @Classname JDKProxyClient
 * @Description jdk动态代理:接口新增方法之后可以直接调用
 * jdk代理源码解析:1.调用Proxy.newProxyInstance  （查找或生成指定的代理类。）
 *                 2.Proxy.newProxyInstance去调用getProxyClass0 调用--> ProxyClassFactory 调用-->ProxyGenerator
 *                 3.Java的反射newInstance  (new出一个实例)
 * @Date 2019/9/24 16:55
 */
public class JDKProxyClient {

    public static void main(String[] args) {
        //生成代理类
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles","true");
        Subject subject = (Subject) Proxy.newProxyInstance(JDKProxyClient.class.getClassLoader(),new Class[]{Subject.class},new JDkProxySubject(new SubjectImpl()));
        subject.access();
    }
}
